package com.bankLogisticsSys.controller;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bankLogisticsSys.interceptor.ManageLoginInterceptor;
import com.bankLogisticsSys.model.Expressprocess;
import com.bankLogisticsSys.service.CreateMsgService;
import com.bankLogisticsSys.service.ExpressService;
import com.bankLogisticsSys.service.ManageExpressService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
@Before(ManageLoginInterceptor.class)
public class ManageExpressController extends Controller{
	
	ManageExpressService service = new ManageExpressService();
	CreateMsgService msgservice = new CreateMsgService();
	ExpressService exservice = new ExpressService();
	protected int page=1;
	protected int rows=20;
	protected long totalCount;
	public static final int WHOLE_SITUATION = 10;
	
	public void expressList(){
		page = getParaToInt("page", 1);
		rows = getParaToInt("rows", 20);
		int bank = getSessionAttr("bank");
		int state = getParaToInt("expressinfo.state", WHOLE_SITUATION);
		int abnormal = getParaToInt("expressinfo.abnormal", WHOLE_SITUATION);
		int flag = getParaToInt("expressinfo.flag", WHOLE_SITUATION);
		java.util.Date date = getParaToDate("expressinfo.sendDate",new java.util.Date(System.currentTimeMillis()));
		Date currentDate = new Date(date.getTime());
		List<Record> list = service.getExpressList(currentDate, page, rows, flag, state, abnormal,bank);
		totalCount = service.getCount(currentDate);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", totalCount);
		map.put("rows", list);
		renderJson(map);
	}
	
	public void list(){
		render("/WEB-INF/content/express/list.html");
	}
	public void detail(){
		long trackingID = getParaToLong("expressinfo.trackingID");
		List<Expressprocess> list = exservice.getProcessList(trackingID);
		List<Map<String, String>> epList = msgservice.getExpressLine(list, exservice.getInfoByTrackingID(trackingID));
		setAttr("epList", epList);
		render("/WEB-INF/content/express/detail.html");
	}
}
